package deprecated;
import Gender;
import Height;
import TreatmentRecord;
import User;

import java.sql.Date;
import java.sql.Time;
import java.util.ArrayList;

/**
 * CRUDUserTool is a tool for creating, reading, updating, and deleting user information on a database.
 * 
 * @author Joshua Harris
 *
 */
public class CRUDUserTool {
	
	private User user;
	private TreatmentRecord record;
	
	/**
	 * This creates a new CRUDUserTool with no user currently being worked on.
	 */
	public CRUDUserTool(){
		user = null;
		record = null;
	}
	
	
	
	/*  
	 *   1)  Create a new User.
	 *   2)  Search for a User in the database.
	 *   3)  Load a User from the list of entries found in the database.
	 *   4)  Store the User's edited data into the database.
	 *   5)  Erases the User's edited data.
	 *   6)  Deletes the User from the database.
	 *   
	 *   readTreatmentRecords()  7)  Retrieves a list of TreatmentRecords from the User.
	 *   8)  Selects a TreatmentRecord from the list by indice.
	 *   9)  Selects the newest TreatmentRecord from the list.
	 *   10) Adds a new TreatmentRecord to the list.
	 *   
	 */
	
	
	
	/**
	 * This loads a new User into the CRUDUserTool.  This does not create a new user unless the user that is currently being worked on has been stored in the database or erased.
	 * 
	 * @return returns true if a new User is created and false if CRUDUserTool could not create a new user.
	 */
	public boolean newUser(){
		if(user == null){
			user = new User();
			return true;
		}
		return false;
	}
	
	public void search(){
		
	}
	
	/**
	 * This loads a user from the user database.  This does not load a user into the CRUDUserTool if the user can not be found in the database or the user that is
	 * currently being worked on in the database has been stored into the database or erased.
	 * 
	 * @return returns true if user is loaded into CRUDUserTool and false if the user is not loaded.
	 */
	public boolean loadUser(){
		if(user == null){
			//user = database.load();
			if(user != null){
				return true;
			}
		}
		return false;
	}
	
	/**
	 * Stores the user that is currently being worked on.
	 * 
	 * @return returns true if the user was stored into the database or false if the user could not be stored into the database or is null.
	 */
	public boolean storeUser(){  // needs more work if user exists in database already
		if(user != null){
			//database.save(user)
			// check if user was stored
			user = null;
			record = null;
			return true;
		}
		return false;
	}
	
	/**
	 * Erases the current user that is being worked on.
	 */
	public void eraseUser(){
		user = null;
		record = null;
	}
	
	/**
	 * deletes a user from the database.
	 */
	public void deleteUser(){
		// deletes the user from the database
	}
	
	/**
	 * Selects a TreatmentRecord from the list of TreatmentRecords of the User.  The TreatmentRecord at index 0 is the newest TreatmentRecord and the oldest is at index size()-1.
	 * 
	 * @param indice the index of the TreatmentRecord to be edited.
	 * @return true if the TreatmentRecord is retrieved and false if the TreatmentRecord could not be retrieved.
	 */
	public boolean selectTreatmentRecord(int index){
		if(user != null){
			record = user.getTreatmentRecords().get(index);
			if(record != null){
				return true;
			}
		}
		return false;
	}
	
	/**
	 * Selects the newest TreatmentRecord of the User.
	 * 
	 * @return true if the TreatmentRecord could be obtained and false if it could not.
	 */
	public boolean selectNewestRecord(){
		if(user != null){
			record = user.getNewestTreatment();
			if(record != null){
				return true;
			}
		}
		return false;
	}
	
	/**
	 * Creates a new TreatmentRecord to be used in the 
	 * @return
	 */
	public boolean addNewTreatmentRecord(){
		if(user != null){
			record = new TreatmentRecord();
			user.addTreatmentRecord(record);
			return true;
		}
		return false;
	}
	
	/**
	 * Checks if there is currently a User to be worked on.
	 * 
	 * @return true if there is a User to be worked on and false if there is not a user to be worked on.
	 */
	public boolean hasUser(){
		if(user == null){
			return false;
		}
		return true;
	}
	
	/**
	 * Checks if there is currently a TreatmentRecord to be worked on.
	 * 
	 * @return true if there is a TreatmentRecord to be worked on and false if there is not a TreatmentRecord to be worked on.
	 */
	public boolean hasTreatmentRecord(){
		if(record == null){
			return false;
		}
		return true;
	}
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	/* **************************************************************************************
	 * **************************************************************************************
	 * 										Update Methods
	 * **************************************************************************************
	 * **************************************************************************************
	 */
	
	
	/**
	 *  updates the users username.
	 *  
	 *  @param username the new username of the user.
	 */
	public void updateUserName(String userName){
		if(user != null){
			user.setUserName(userName);
		}
	}
	
	/**
	 * updates the password.
	 * 
	 * @param password the new password of the user.
	 */
	public void updatePassword(String password){
		if(user != null){
			user.setPassword(password);
		}
	}
	
	/**
	 * updates the suspend status of the user.
	 * 
	 * @param suspend the new suspend status of the user.
	 */
	public void updateSuspended(boolean suspend){
		if(user != null){
			user.setSuspended(suspend);
		}
	}
	
	/**
	 * updates the roles that the user can enter the system as.  [patient, nurse, doctor, admin].
	 * 
	 * @param roles the boolean[4] that represents which roles the user can login as.
	 */
	public void updateRoles(boolean[] roles){
		if(user != null){
			user.setRoles(roles);
		}
	}
	
	/**
	 * updates the users name.
	 * 
	 * @param name the name of the user.
	 */
	public void updateName(String name){
		if(user != null){
			user.setName(name);
		}
	}
	
	/**
	 * updates the address that the user lives at.
	 * 
	 * @param address the new address of the user.
	 */
	public void updateAddress(String address){
		if(user != null){
			user.setAddress(address);
		}
	}
	
	/**
	 * updates the phone number of the user.
	 * 
	 * @param phone the new phone number of the user.
	 */
	public void updatePhone(String phone){
		if(user != null){
			user.setPhone(phone);
		}
	}
	
	/**
	 * updates the cell phone number of the user.
	 * 
	 * @param cellPhone the new cell phone number of the user.
	 */
	public void updateCellPhone(String cellPhone){
		if(user != null){
			user.setCellPhone(cellPhone);
		}
	}
	
	/**
	 * updates the email address of the user.
	 * 
	 * @param email the new email address of the user.
	 */
	public void updateEmail(String email){
		if(user != null){
			user.setEmail(email);
		}
	}
	
	/**
	 * updates the gender of the user.
	 * 
	 * @param gender the new gender of the user.
	 */
	public void updateGender(Gender gender){
		if(user != null){
			user.setGender(gender);
		}
	}
	
	/**
	 * updates the birthdate of the user.
	 * 
	 * @param date the new birthdate of the user.
	 */
	public void updateBirthdate(Date date){
		if(user != null){
			user.setBirthDate(date);
		}
	}
	
	/**
	 * updates the pharmacy of the user.
	 * 
	 * @param pharmacy the new pharmacy of the user.
	 */
	public void updatePharmacy(String pharmacy){
		if(user != null){
			user.setPharmacy(pharmacy);
		}
	}
	
	/**
	 * updates the insurance carrier of the user.
	 * 
	 * @param insurance the new insurance carrier of the user.
	 */
	public void updateInsurance(String insurance){
		if(user != null){
			user.setInsurance(insurance);
		}
	}
	
	/**
	 * updates the allergies of the user.
	 * 
	 * @param allergies the updated allergies of the user.
	 */
	public void updateAllergies(String allergies){
		if(user != null){
			user.setAllergies(allergies);
		}
	}
	
	/**
	 * updates the treating doctor on the TreatmentRecord.
	 * 
	 * @param doctor the updated treating doctor of TreatmentRecord.
	 */
	public void updateTreatingDoctor(String doctor){
		if(record != null){
			record.setTreatingDoctor(doctor);
		}
	}
	
	/**
	 * updates the date on the TreatmentRecord.
	 * 
	 * @param date the date that the Treatment took place.
	 */
	public void updateDate(Date date){
		if(record != null){
			record.setDate(date);
		}
	}
	
	/**
	 * updates the time on the TreatmentRecord.
	 * 
	 * @param time the time that the treatment took place.
	 */
	public void updateTime(Time time){
		if(record != null){
			record.setTime(time);
		}
	}
	
	/**
	 * updates the attending nurse on the TreatmentRecord.
	 * 
	 * @param nurse the attending nurse during the treatment.
	 */
	public void updateAttendingNurse(String nurse){
		if(record != null){
			record.setAttendingNurse(nurse);
		}
	}
	
	/**
	 * updates the symptoms on the TreatmentRecord.
	 * 
	 * @param symptoms the symptoms on the treatment record.
	 */
	public void updateSymptoms(String symptoms){
		if(record != null){
			record.setSymptoms(symptoms);
		}
	}
	
	/**
	 * updates the Systolic Blood Pressure at the time of treatment.
	 * 
	 * @param bps the systolic blood pressure on the treatment record.
	 */
	public void updateBpSystolic(int bps){
		if(record != null){
			record.setBpSystolic(bps);
		}
	}
	
	/**
	 * updates the diastolic blood pressure at the time of treatment.
	 * 
	 * @param bpd the diastolic blood pressure on the treatment record.
	 */
	public void updateBpDiastolic(int bpd){
		if(record != null){
			record.setBpDiastolic(bpd);
		}
	}
	
	/**
	 * updates the pulse of the user at the time of the treatment.
	 * 
	 * @param pulse the pulse of the user at the time of the treatment.
	 */
	public void updatePulse(int pulse){
		if(record != null){
			record.setPulse(pulse);
		}
	}
	
	/**
	 * updates the temperature of the user at the time of treatment.
	 * 
	 * @param temp the temperature of the user at the time of treatment.
	 */
	public void updateTemperature(double temp){
		if(record != null){
			record.setTemperature(temp);
		}
	}
	
	/**
	 * updates the height of the user at the time of treatment.
	 * 
	 * @param height the height of the user at the time of treatment.
	 */
	public void updateHeight(Height height){
		if(record != null){
			record.setHeight(height);
		}
	}
	
	/**
	 * updates the weight of the user at the time of treatment.
	 * 
	 * @param weight the weight of the user at the time of treatment.
	 */
	public void updateWeight(double weight){
		if(record != null){
			record.setWeight(weight);
		}
	}
	
	/**
	 * updates the diagnosis of the treatment.
	 * 
	 * @param diagnosis the diagnosis of the treatment.
	 */
	public void updateDiagnosis(String diagnosis){
		if(record != null){
			record.setDiagnosis(diagnosis);
		}
	}
	
	/**
	 * updates the prescription to be done on the Doctor's Order of the TreatmentRecord.
	 * 
	 * @param prescription the prescription information that will be used.
	 */
	public void updatePrescription(String prescription){
		if(record != null){
			record.setPrescription(prescription);
		}
	}
	
	/**
	 * updates the Labwork that needs to be done on the Doctor's Order of the TreatmentRecord.
	 * 
	 * @param labwork the labwork that needs to be done.
	 */
	public void updateLabWork(String labwork){
		if(record != null){
			record.setLabWork(labwork);
		}
	}
	
	/**
	 * updates the follow up instructions of the TreatmentRecord's Doctor's Order.
	 * 
	 * @param fui the new Follow up instructions.
	 */
	public void updateFollowUpInstructions(String fui){
		if(record != null){
			record.setFollowUpInstructions(fui);
		}
	}
	
	/**
	 * updates the other instructions on the TreatmentRecord's Doctor's Order.
	 * 
	 * @param oi the new Other Instructions.
	 */
	public void updateOtherInstructions(String oi){
		if(record != null){
			record.setOtherInstructions(oi);
		}
	}
	
	
	
	
	/* *********************************************************************************************
	 * *********************************************************************************************
	 * 						Read Methods
	 * *********************************************************************************************
	 * *********************************************************************************************
	 */
	
	
	/**
	 * reads the user.
	 * 
	 * @return the User that holds the users data.
	 */
	public User readUser(){
		return user;
	}
	
	/**
	 * reads the username of the user.
	 * 
	 * @return the username of the user.
	 */
	public String readUsername(){
		if(user != null){
			return user.getUserName();
		}
		return null;
	}
	
	/**
	 * reads the password of the user.
	 * 
	 * @return the password of the user.
	 */
	public String readPassword(){
		if(user != null){
			return user.getPassword();
		}
		return null;
	}
	
	/**
	 * reads the suspension state of the user.
	 * 
	 * @return the suspension state of the user.
	 */
	public boolean readSuspended(){
		if(user != null){
			return user.getSuspended();
		}
		return false;
	}
	
	/**
	 * reads the roles that the user can login as.  [patient, nurse, doctor, admin].
	 * 
	 * @return boolean[4] of the roles that the user can log in as.
	 */
	public boolean[] readRoles(){
		if(user != null){
			return user.getRoles();
		}
		return new boolean[0];
	}
	
	/**
	 * reads the name of the user.
	 * 
	 * @return the name of the user.
	 */
	public String readName(){
		if(user != null){
			return user.getName();
		}
		return null;
	}
	
	/**
	 * reads the address that the user lives at.
	 * 
	 * @return the address that the user lives at.
	 */
	public String readAddress(){
		if(user != null){
			return user.getAddress();
		}
		return null;
	}
	
	/**
	 * reads the phone number of the user.
	 * 
	 * @return the phone number of the user.
	 */
	public String readPhone(){
		if(user != null){
			return user.getPhone();
		}
		return null;
	}
	
	/**
	 * reads the cell phone number of the user.
	 * 
	 * @return the cell phone number of the user.
	 */
	public String readCellPhone(){
		if(user != null){
			return user.getCellPhone();
		}
		return null;
	}
	
	/**
	 * reads the email address of the user.
	 * 
	 * @return the email address of the user.
	 */
	public String readEmail(){
		if(user != null){
			return user.getEmail();
		}
		return null;
	}
	
	/**
	 * reads the Gender of the user.
	 * 
	 * @return the Gender of the user.
	 */
	public Gender readGender(){
		if(user != null){
			return user.getGender();
		}
		return null;
	}
	
	/**
	 * reads the birthdate of the user.
	 * 
	 * @return the birthdate of the user.
	 */
	public Date readBirthDate(){
		if(user != null){
			return user.getBirthDate();
		}
		return null;
	}
	
	/**
	 * reads the age of the user.
	 * 
	 * @return the age of the user.
	 */
	/*public int readAge(){
		if(user != null){
			return user.getAge();
		}
		return 0;
	}*/
	
	/**
	 * reads the pharmacy of the user.
	 * 
	 * @return the pharmacy of the user.
	 */
	public String readPharmacy(){
		if(user != null){
			return user.getPharmacy();
		}
		return null;
	}
	
	/**
	 * reads the insurance of the user.
	 * 
	 * @return the insurance of the user.
	 */
	public String readInsurance(){
		if(user != null){
			return user.getInsurance();
		}
		return null;
	}
	
	/**
	 * reads the allergies of the user.
	 * 
	 * @return the allergies of the user.
	 */
	public String readAllergies(){
		if(user != null){
			return user.getAllergies();
		}
		return null;
	}
	
	/**
	 * reads the newest TreatmentRecord of the user.
	 * 
	 * @return the newest TreatmentRecord of the user.
	 */
	public TreatmentRecord readNewestTreatment(){
		if(user != null){
			return user.getNewestTreatment();
		}
		return null;
	}
	
	/**
	 * reads the TreatmentRecords of the user.
	 * 
	 * @return the TreatmentRecords of the user.
	 */
	public ArrayList<TreatmentRecord> readTreatmentRecords(){
		if(user != null){
			return user.getTreatmentRecords();
		}
		return null;
	}
	
	/**
	 * reads the Treating Doctor during the treatment.
	 * 
	 * @return the treating doctor during the treatment.
	 */
	public String readTreatingDoctor(){
		if(record != null){
			return record.getTreatingDoctor();
		}
		return null;
	}
	
	/**
	 * reads the date of the treatment.
	 * 
	 * @return the date that the treatment occured.
	 */
	public Date readDate(){
		if(record != null){
			return record.getDate();
		}
		return null;
	}
	
	/**
	 * reads the time of the treatment.
	 * 
	 * @return the time that the treatment occured.
	 */
	public Time readTime(){
		if(record != null){
			return record.getTime();
		}
		return null;
	}
	
	/**
	 * reads the attending nurse during the treatment.
	 * 
	 * @return the attending nurse during the treatment.
	 */
	public String readAttendingNurse(){
		if(record != null){
			return record.getAttendingNurse();
		}
		return null;
	}
	
	/**
	 * reads the symptoms of the user during the treatment.
	 * 
	 * @return the symptoms of the user during the treatment.
	 */
	public String readSymptoms(){
		if(record != null){
			return record.getSymptoms();
		}
		return null;
	}
	
	/**
	 * reads the systolic blood pressure of the user during the treatment.
	 * 
	 * @return the systolic blood pressure of the user during the treatment.
	 */
	public int readBpSystolic(){
		if(record != null){
			return record.getBpSystolic();
		}
		return 0;
	}
	
	/**
	 * reads the diastolic blood pressure of the user during the treatment.
	 * 
	 * @return the diastolic blood pressure of the user during the treatment.
	 */
	public int readBpDiastolic(){
		if(record != null){
			return record.getBpDiastolic();
		}
		return 0;
	}
	
	/**
	 * reads the pulse of the user during the treatment.
	 * 
	 * @return the pulse of the user during the treatment.
	 */
	public int readPulse(){
		if(record != null){
			return record.getPulse();
		}
		return 0;
	}
	
	/**
	 * reads the temperature of the user during the treatment.
	 * 
	 * @return the temperature of the user during the treatment.
	 */
	public double readTemperature(){
		if(record != null){
			return record.getTemperature();
		}
		return 0.0;
	}
	
	/**
	 * reads the height of the user at the time of treatment.
	 * 
	 * @return the height of the user at the time of treatment.
	 */
	public Height readHeight(){
		if(record != null){
			return record.getHeight();
		}
		return null;
	}
	
	/**
	 * reads the weight of the user at the time of treatment.
	 * 
	 * @return the weight of the user at the time of treatment.
	 */
	public double readWeight(){
		if(record != null){
			return record.getWeight();
		}
		return 0.0;
	}
	
	/**
	 * reads the diagnosis of the treatment.
	 * 
	 * @return the diagnosis of the treatment.
	 */
	public String readDiagnosis(){
		if(record != null){
			return record.getDiagnosis();
		}
		return null;
	}
	
	/**
	 * reads the prescription given by the TreatmentRecord's Doctor's Order.
	 * 
	 * @return the prescription given by the TreatmentRecord's Doctor's Order.
	 */
	public String readPrescription(){
		if(record != null){
			return record.getPrescription();
		}
		return null;
	}
	
	/**
	 * reads the labwork that will be done.
	 * 
	 * @return the labwork that will be done.
	 */
	public String readLabWork(){
		if(record != null){
			return record.getLabWork();
		}
		return null;
	}
	
	/**
	 * reads the follow up instructions that will be done by the patient.
	 * 
	 * @return the follow up instructions.
	 */
	public String readFollowUpInstructions(){
		if(record != null){
			return record.getFollowUpInstructions();
		}
		return null;
	}
	
	/**
	 * reads the other instructions that will be done by the patient.
	 * 
	 * @return the other instructions.
	 */
	public String readOtherInstructions(){
		if(record != null){
			return record.getOtherInstructions();
		}
		return null;
	}
	
}